package com.rongc.client.freight.base.view.widget.CJRow;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.rongc.client.core.log.CCLog;
import com.rongc.client.core.utils.SPUtil;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.core.utils.SystemUtil;
import com.rongc.client.freight.R;
import com.rongc.client.freight.UniApplication;
import com.rongc.client.freight.base.model.DicsBean;
import com.rongc.client.freight.utils.dic.IField;
import com.rongc.client.freight.utils.dic.impl.Field;
import com.rongc.client.freight.utils.dic.impl.FieldConstant;
import com.rongc.client.freight.utils.dic.impl.Table;
import com.umeng.message.MsgConstant;
import com.umeng.message.PushAgent;

import java.util.List;


public class CustomCJRowAdapter extends BaseAdapter implements OnClickListener {
	private Activity activity;
	private LayoutInflater inflater;
	private CJRow cjrow;
	private int height; // 项高度
	private ARResponse response=new ARResponse();
	private Table table=new Table();

	private List<Field> fields;
	private boolean isedit = false; // 编辑本页面标识
	private int index = -1; // 选中项下标
	// private boolean isInit = true;
	private View view = null; // 编辑项控件的引用
//	private CJPopupWindow manage; // popupwindow管理类
//	private CJRowCompsFactory factory; // popupwindow中组件工厂类

	private int layoutID;
	protected int[] mTo; // 第一列展示列，第二列展示值
	protected CJRowListener seedListener;
	protected ViewBinder mViewBinder;
	protected ViewBinder mLableBinder;
	private InputMethodManager imm;

	public CustomCJRowAdapter(Activity activiay, CJRow cjrow, Table table, ARResponse response) {
		try {
			this.activity = activiay;
			this.height = 46;
			this.inflater = LayoutInflater.from(activiay);
			this.cjrow = cjrow;
			this.table = table;
			this.response = response;
			this.fields = this.table.getFieldList();
			this.layoutID = R.layout.cjitem2;
			this.mTo = new int[] { R.id.title, R.id.lablevalue };

			imm = (InputMethodManager) activiay
					.getSystemService(Context.INPUT_METHOD_SERVICE);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		initFirstandEndPosition();
	}

	public CustomCJRowAdapter(Activity activiay, CJRow cjrow, Table table, ARResponse response,
			int layoutID, int[] to) {
		this(activiay, cjrow, table, response);
		this.layoutID = layoutID;
		this.mTo = to;
	}

	public CustomCJRowAdapter(Activity activiay, CJRow cjrow, Table table, ARResponse response,
			int layoutID, int[] to, int height) {
		this(activiay, cjrow, table, response, layoutID, to);
		this.height = height;
	}
	
	public void setCJRowListener(CJRowListener seedListener) {
		this.seedListener = seedListener;
	}
	
	public void setFieldvalue(int position, String value) {
		response.update(fields.get(position).getFieldName(),
				value);
	}

	public void setFieldvalue(String fieldName, String value) {
		CCLog.e("ccqx", "setFieldvalue"+fieldName+"  ----  value"+value);
		response.update(fieldName, value);
	}
	
	public void refresh(ARResponse response){
		this.response = response;
		notifyDataSetChanged();
	}

	public void setViewBinder(ViewBinder binder) {
		this.mViewBinder = binder;
	}
	
	public void setLableBinder(ViewBinder binder){
		this.mLableBinder = binder;
	}

	// 返回高度，计算list高度
	public int getHeight() {
		return this.height;
	}

	public int getCount() {
		int counts = 0;
		if (fields != null){
			/*for (int i = 0; i < fields.size(); i++) {
				if (fields.get(i).canShow())
					counts++;
			}*/
			return fields.size();
		}else
			return 0;
	}

	public int getGroup(int index){
		return fields.get(index).getGroupId();
	}

	public int getGroupCount(){
		int groupid = -99;
		int groupcount = 0;
		for (int i = 0; i < fields.size(); i++) {
			if(fields.get(i).canShow())
			if(groupid != getGroup(i)){
				groupid = getGroup(i);
				groupcount ++ ;
			}
		}
		return groupcount;
	}
	
	// ----设置圆倒角背景  begin
	int first = -1 ,end = -1;
	private void setFirstandEndPosition(){
		if(fields == null) return;
		for (int i = 0; i < fields.size(); i++) {
			if(first<0){
				if(fields.get(i).canShow())
					first = i;
			}
		}
		
		for (int i = fields.size() - 1; i >= 0; i--) {
			if(end<0){
				if(fields.get(i).canShow())
					end = i;
			}
		}
	}
	
	private void initFirstandEndPosition(){
		first = -1;
		end = -1;
		setFirstandEndPosition();
	}
	
	private void setBackground(View v ,int position ,Field field){
		if (getCount() == 1) {
			v.setBackgroundDrawable(cjrow.bgsingle);
		}
		// 第一项
		else if (position == first) {
			v.setBackgroundDrawable(cjrow.bgtop);
		}
		// 最后一项
		else if (position == end) {
			v.setBackgroundDrawable(cjrow.bgbottom);
		} else {
			v.setBackgroundDrawable(cjrow.bgcenter);
		}
	}
	// ----设置圆倒角背景 end

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	/**
	 * 画列表的项，根据下标iIndex判断选中项与普通项并赋值
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = createViewFromResource(position, convertView, parent, layoutID);

		// if (isedit) {
		// if (position == index) { // 编辑项的布局
		// if (setEdit()){
		// ((RelativeLayout) convertView).addView(view);
		// }
		// } else {
		//
		// }
		// }

		return v;
	}

	protected View createViewFromResource(int position, View convertView,
			ViewGroup parent, int resource) {
		convertView = null;
		View v = inflater.inflate(resource, parent, false);

//		if (position==0) {
//			v.setBackgroundResource(R.drawable.me_list_cent_normal_first);
//		} else {
//			v.setBackgroundResource(R.drawable.me_list_cent_normal);
//		}
		v.setLayoutParams(new AbsListView.LayoutParams(
				LayoutParams.FILL_PARENT, SystemUtil.dip2px(activity, height)));
		bindView(position, v);
		
		v.setOnClickListener(this);
		
		return v;
	}
	
	// 绑定一项（一项包含键和值）
	private void bindView(int position, View view) {
		Field field = fields.get(position);
		boolean canshow = field.canShow();

		if(!canshow){
			view.setVisibility(View.GONE);
			return;
		}
		
		bindLable(position, view, field);
		bindValue(position, view, field);
		view.setTag(field);
		//屏蔽倒角
		if(cjrow.hascorner)
			setBackground(view,position,field);
		
	}

	// 绑定键列
	private void bindLable(int position, View view, Field field) {
		if (mLableBinder != null) {
			boolean bound = mLableBinder.setViewValue(view, field.getLabel(), position,
					field.getFieldName());
			
			if(bound) return;
		}
		final View v = view.findViewById(mTo[0]);
		if (v instanceof TextView) {
			setViewText((TextView) v, field.getLabel());
			if(field.getFieldIcon() != 0){
				((TextView) v).setCompoundDrawablesWithIntrinsicBounds(
						activity.getResources().getDrawable(field.getFieldIcon()),
						null,null,null);

			}
		}else if(v instanceof ImageView){
			setViewImage((ImageView) v, field.getLabel());
		}

		// 必选项
		boolean isNullable = field.isNullable();
		if (!isNullable) {
			/*TextView tv = new TextView(activity);
			RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			layoutparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
			layoutparams.leftMargin = 10;
			layoutparams.addRule(RelativeLayout.CENTER_VERTICAL);
			tv.setTextColor(0xffff0000);
			tv.setText("*");
			tv.setLayoutParams(layoutparams);
			((RelativeLayout) view).addView(tv);*/
		}

	}

	private boolean isloaded = false;

	// 绑定值列
	private void bindValue(final int position, final View view,
			final Field field) {

		if (response == null) {
			isloaded = false;
			return;
		}
		// 没有数据
		if (response.getRowNum() == 0) {
			// TODO 加效果
			isloaded = false;
			((TextView) view.findViewById(mTo[1])).setText("请稍后...");
			return;
		}
		isloaded = true;
		final View v = view.findViewById(mTo[1]);
		ViewBinder binder = mViewBinder;

		// 对应的数据字典
		String functionNo = field.getFunctionNo();
		String content = "";

		if (StringUtils.isEmpty(functionNo)) {
			content = response.getValue(field.getFieldName());
		} else {
			content = getValueByField(response.getValue(field.getFieldName()),field);
		}
		content = content == null ? "" : content.toString();
		// 是否为可编辑状态
		boolean editable = field.isEditable();
		// 显示类型
		int showtype = field.getShowType();
		// 输入类型
		int inputtype = field.getInputType();
//		CCLog.e("ccqx","content---->"+content+"showtype"+showtype+"editable"+editable+"inputtype"+inputtype);
		if (!editable) { // 不可编辑
			((TextView) v).setText(content);
			/*((TextView) v).setTextColor(activity.getResources().getColor(
					R.color.danlanse));*/
			/*((TextView) v).setTextColor(activity.getResources().getColor(
					R.color.cj_customersInfo_color));*/
			if (inputtype == FieldConstant.INPUTTYPE_SINGLE) {
				((TextView) v).setSingleLine(true);
			} else if (inputtype == FieldConstant.INPUTTYPE_MULTIPLE) {
				((TextView) v).setSingleLine(false);
			}
		} else if (showtype == FieldConstant.SHOWTYPE_JUMP_ACTIVITY) { // 可编辑但不在本页面，跳ACTIVITY方式
			/*if (content.equals("")) {
				if (field.getLabel() != null && field.getLabel().length() <= 6)
					((TextView) v).setText("请选择" + field.getLabel());
				else
					((TextView) v).setText("请选择");
			}else*/
				((TextView) v).setText(content);


			((TextView) v).setCompoundDrawablesWithIntrinsicBounds(
					null,null,activity.getResources().getDrawable(R.mipmap.arrow_right1),null);
			/*ImageView iv = new ImageView(activity);
			RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
			layoutparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
			layoutparams.rightMargin = 10;
			iv.setLayoutParams(layoutparams);
			iv.setImageResource(R.mipmap.arrow_right1);
			iv.setScaleType(ScaleType.CENTER_INSIDE);
			((RelativeLayout) view).addView(iv);*/
		} else if (showtype != FieldConstant.SHOWTYPE_NO_CLICK) { // 可编辑，弹POPUPWINDOW方式 或 页面编辑
			// TODO 添加效果

			((TextView) v).setText(content);
			if(field.getLabel() !=null && field.getLabel().length() <= 6)
				((TextView) v).setHint("请输入" + field.getLabel());
			else
				((TextView) v).setHint("请输入");
		} else { // 按输入类型NEW出不同类型的控件
			View seed = null;
			if (inputtype == FieldConstant.INPUTTYPE_UNKNOWN) {
				
			}else if (inputtype == FieldConstant.INPUTTYPE_NOCHANGE) {
					
			}else if (inputtype == FieldConstant.INPUTTYPE_SINGLE) {
				((ViewGroup)view).removeViewInLayout(v);
				v.setVisibility(View.GONE);
				ViewGroup.LayoutParams layoutparams = (ViewGroup.LayoutParams) v
						.getLayoutParams();
				int inputStyle = field.getInputStyle();
				seed = new EditText(activity);
				layoutparams.width = LayoutParams.MATCH_PARENT;
				seed.setId(v.getId());
				seed.setLayoutParams(layoutparams);
				seed.setBackgroundResource(R.color.transparent);
				((EditText) seed).setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
				((EditText) seed).setTextSize(TypedValue.COMPLEX_UNIT_PX,((TextView)v).getTextSize());
				((EditText) seed).setText(content);
				((EditText) seed).setSingleLine(true);
				if(inputStyle != 0)
					((EditText) seed).setInputType(inputStyle);
//					((EditText) seed).setContentColor(Color.BLACK);
				seed.setTag(position);

				if(field.getLabel() !=null && field.getLabel().length() <= 6)
					((EditText) seed).setHint("请输入" + field.getLabel());
				else
					((EditText) seed).setHint("请输入");

				((EditText) seed).addTextChangedListener(new TextWatcher() {
					
		        	@Override
					public void onTextChanged(CharSequence s, int start, int before, int count) {
					}
					
					@Override
					public void beforeTextChanged(CharSequence s, int start, int count,
							int after) {
					}
					
					@Override
					public void afterTextChanged(Editable s) {
						setFieldvalue(index, s.toString());
					}
				});
				
				((EditText) seed).setOnFocusChangeListener(new OnFocusChangeListener() {
					
					public void onFocusChange(View v, boolean hasFocus) {
						if(!hasFocus){
						}else{
							index = StringUtils.parseInt(v.getTag()
									.toString());
						}
					}
				});
				
			} else if (inputtype == FieldConstant.INPUTTYPE_RADIO) {
				((ViewGroup)view).removeViewInLayout(v);
				v.setVisibility(View.GONE);
//				RelativeLayout.LayoutParams layoutparams = (RelativeLayout.LayoutParams) v
//						.getLayoutParams();
				RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
				seed = new Switch(activity);
//				layoutparams.width = LayoutParams.WRAP_CONTENT;
				layoutparams.rightMargin = 10;
				layoutparams.addRule(RelativeLayout.CENTER_VERTICAL);
				layoutparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
				seed.setLayoutParams(layoutparams);
				seed.setTag(position);
				seed.setId(v.getId());
				((Switch)seed).setSwitchMinWidth(SystemUtil.dip2px(activity,40));
				((Switch)seed).setTextOn(" ");
				((Switch)seed).setTextOff(" ");
				((Switch)seed).setThumbResource(R.drawable.thumb);
				((Switch)seed).setTrackResource(R.drawable.track);
				((Switch)seed).setChecked(SPUtil.getBoolean("mute",false));
				((Switch)seed).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
						SPUtil.putBoolean("mute",isChecked);
						PushAgent mPushAgent = PushAgent.getInstance(UniApplication.getInstance());
						if(isChecked) {
							mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_DISABLE);
						}
						else {
							mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_ENABLE);
						}
					}
				});
				/*((CJSexChoose) seed)
						.setOnChooseListener(new ChooseListener() {

							@Override
							public void onChoosed(int checked, View v) {
								index = StringUtil.parseInt(v.getTag()
										.toString());
								setFieldvalue(index, checked + "");
							}
						});
*/
			} 
				// TODO 内部添加其他类型（也可以在通过外部设定绑定器绑定）
			if (seed != null) ((ViewGroup) view).addView(seed);
		}
		

		// 用外部设定的绑定器绑定
		if (binder != null) {
			binder.setViewValue(view, content, position,
					field.getFieldName());
		}
	}

	private void setViewImage(ImageView v, String value) {
		try {
			v.setImageResource(Integer.parseInt(value));
		} catch (NumberFormatException nfe) {
			v.setImageURI(Uri.parse(value));
		}
	}

	private void setViewText(TextView v, String text) {
		v.setText(text);
	}

	@Override
	public void onClick(View v) {
		CCLog.e("ccqx", "onclick");
		
		if (!isloaded) return;

		CCLog.e("ccqx", "onclick 1");
		if (updateAndNotify()) {
			imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
			return;
		}
		CCLog.e("ccqx", "onclick 2");

		Field field = (Field) ((v).getTag());
		int showtype = field.getShowType();
		CCLog.e("ccqx", "onclick "+showtype);
		index = fields.indexOf(field);
		v.setFocusable(true);
		v.setFocusableInTouchMode(true);
		v.requestFocus();
		switch (showtype) { // 0: 无点击即显示 1:点击后当前页面编辑 2：点击后跳转activity
							// 3:点击后跳转popupWindow
		case FieldConstant.SHOWTYPE_CLICK:
			if (seedListener != null)
				if (seedListener.seedAction(index,field, response.getValue(fields.get(index).getFieldName()))) break;

			isedit = true;
			notifyDataSetChanged();
			break;
		case FieldConstant.SHOWTYPE_JUMP_ACTIVITY:
			makeActivityByField(field);
			break;
		case FieldConstant.SHOWTYPE_JUMP_PW:
//			imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
			if (seedListener != null)
				if (seedListener.popupWindowAction(field, response.getValue(fields.get(index).getFieldName()))) break;
			/*
			if(field.getInputType() == 7 || field.getInputType() == 8)
				makePopupWindowByField(field, mainHander).showAtLocation(v,
					Gravity.BOTTOM, 0, 0);
			else
				makePopupWindowByField(field, mainHander).showAtLocation(v,
						Gravity.CENTER, 10, 10);
			break;*/
		default:
			// Toast.makeText(activity, "Click on---->" + index + "项",
			// Toast.LENGTH_LONG).show();
			break;
		}
	}

	// 取消页面中修改状态并将值更新到界面
	 private boolean updateAndNotify() {
		if (isedit) {
			isedit = false;
			String rlt = getResult();
			boolean isnullable = fields.get(index).isNullable();
			if (!isnullable && rlt.equals("")) {
				// Toast.makeText(activity, "不能为空", Toast.LENGTH_SHORT).show();
			} else {
				IField field = fields.get(index);
				int inputtype = field.getInputType();
				if (inputtype != 0) // 编辑框不在这里修改
					setFieldvalue(index, rlt);
			}
			notifyDataSetChanged();
			return true;
		}
		return false;
	} 

	private String getValueByField(String key,Field type) {
		String showValue = key;
		DicsBean beans = DicsBean.load(type.getFunctionNo());

		if(beans != null)
			for (DicsBean.DicBean bean : beans.getDics()) {
				if(key.equals(bean.getKey())){
					showValue = bean.getValue();
					break;
				}
			}
		return showValue;
	}

	/*private Handler mainHander = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				if (manage != null) manage.close();
				// Toast.makeText(activity, "确定事件", Toast.LENGTH_SHORT).show();
				String rlt = msg.obj.toString();
				setFieldvalue(index, rlt);
				notifyDataSetChanged();
				break;
			case 2:
				if (manage != null) manage.close();
				// Toast.makeText(activity, "取消事件", Toast.LENGTH_SHORT).show();
				break;
			case 3:// 一个按钮的事件
					// Toast.makeText(activity, "一个按钮的事件",
					// Toast.LENGTH_SHORT).show();
				break;
			}
		}
	};*/

	private void makeActivityByField(Field field) {
		CCLog.e("ccqx", "makeActivityByField");
		if (seedListener != null)
			if (seedListener.activityAction(field, null)) return;
		/*Bundle bundle = new Bundle();
		String lable = "请选择" + field.getLabel();
		;
		String value = response.getValue(fields.get(index).getFieldName());

		switch (field.getInputType()) {// 9:列表① 10:列表② 11：列表③
		case 0:
		case 1:
			// bundle.putSerializable("field", field);
			// bundle.putString("value",
			// response.getValue(fields.get(index).getFieldName()));
			// bundle.putInt("position", index);
			// ActivityUtil.startActivityForResult(activity,
			// ConfigData.PACKAGENAME + ".demo.CJRowModifyActivity",
			// false, bundle, 0);
			break;
		case FieldConstant.INPUTTYPE_LIST_1:
			bundle.putString("lable", lable); // 用于CJHEAD的显示
			bundle.putSerializable("field", field); // 用于返回时修改response的定位
			bundle.putString("value", value); // 当前选择的值
			bundle.putInt("sum_level", 1); // 一共有几层
			bundle.putInt("curr_level", 1); // 当前第几层
			bundle.putIntArray("functionNO",
					new int[] { field.getFunctionNo() }); // 当前第几层

			// TODO 这里调用统一的Activity，该Activity需要定义规则并统一实现业务
			ActivityUtil.startActivityForResult(activity,
					ConfigData.PACKAGENAME + ".CJCascadeActivity", false,
					bundle, ActivityUtil.request_code_9);
			break;
		case FieldConstant.INPUTTYPE_LIST_2:
			bundle.putString("lable", lable); // 用于CJHEAD的显示
			bundle.putSerializable("field", field); // 用于返回时修改response的定位
			bundle.putString("value", value); // 当前选择的值
			bundle.putInt("sum_level", 2); // 一共有几层
			bundle.putInt("curr_level", 1); // 当前第几层
			bundle.putIntArray("functionNO",
					new int[] { field.getFunctionNo() }); // 当前第几层

			// TODO 这里调用统一的Activity，该Activity需要定义规则并统一实现业务
			ActivityUtil.startActivityForResult(activity,
					ConfigData.PACKAGENAME + ".CJCascadeActivity", false,
					bundle, ActivityUtil.request_code_9);
			break;
		case FieldConstant.INPUTTYPE_LIST_3:

			bundle.putString("lable", lable); // 用于CJHEAD的显示
			bundle.putSerializable("field", field); // 用于返回时修改response的定位
			bundle.putString("value", value); // 当前选择的值
			bundle.putInt("sum_level", 3); // 一共有几层
			bundle.putInt("curr_level", 1); // 当前第几层
			bundle.putIntArray("functionNO",
					new int[] { field.getFunctionNo() }); // 当前第几层

			// TODO 这里调用统一的Activity，该Activity需要定义规则并统一实现业务
			ActivityUtil.startActivityForResult(activity,
					ConfigData.PACKAGENAME + ".CJCascadeActivity", false,
					bundle, ActivityUtil.request_code_9);
			break;
		case 5:
			 
			break;
		default:

			break;
		}*/
	}

	

	/*private PopupWindow makePopupWindowByField(IField field, Handler mainHander) {
		PopupWindow pw = null;
		View view = null;
		manage = new CJPopupWindow(activity, mainHander);
		factory = new CJRowCompsFactory(manage, inflater, mainHander);
		int position = response.getFieldIndex(field.getFieldName());
		boolean iseditable = field.isEditable();
		int inputtype = field.getInputType();
		int inputstyle = field.getInputStyle();
		if (!iseditable) { // 不可编辑
			manage.makePopupWindow(field.getLabel(),
					response.getValue(fields.get(index).getFieldName()), 1);
		} else {
			switch (inputtype) {// 0单行文本1多行文本2数字3浮点数字4单选列表5多选6日期7日期2
//			case 0:
//				view = factory.makeSingleEditText(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindow(300, 200, field.getLabel(), view, 2);
//
//				break;
//			case 1:
//				view = factory.makeRichEditText(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindow(300, 300, field.getLabel(), view, 2);
//				break;
//			case 2:
//				view = factory.makeIntegerSoftKeyboard(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindow(300, 400, field.getLabel(), view, 0);
//				break;
//			case 3:
//				view = factory.makeFloatSoftKeyboard(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindow(300, 400, field.getLabel(), view, 0);
//				break;
//			case 4:
//				view = factory.makeSingleList(activity,
//						response.getValue(fields.get(index).getFieldName()),
//						field);
//				pw = manage
//						.makePopupWindow(300, 300, field.getLabel(), view, 2);
//				break;
//			case 5:
//				view = factory.makeMultipleList(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindow(300, 400, field.getLabel(), view, 2);
//				break;
//			case 6:
//				view = factory.makeCJDate(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindow(300, 200, field.getLabel(), view, 2);
//				break;
			case 7:
				view = factory.makeCJDateWheelView(activity,
						response.getValue(fields.get(index).getFieldName()) ,inputstyle);
				pw = manage
						.makePopupWindowNew(320, 400, field.getLabel(), view, 0);
				break;
//			case 8:
//				view = factory.makeCJWheelDate(activity,
//						response.getValue(fields.get(index).getFieldName()));
//				pw = manage
//						.makePopupWindowNew(320, 400, field.getLabel(), view, 0);
//				break;
//			default:
//				break;
			}
		}

		return pw;
	}*/

	// 获取返回结果
	private String getResult() {
		String strRlt = "";
		if (view == null) return strRlt;
		IField field = fields.get(index);
		int inputtype = field.getInputType();
		switch (inputtype) {
		case 0: // 编辑框
			break;
		case 1: // auto控件
//			strRlt = ((CJIntScanf) view).getText() + "";
			break;
		case 2: // 开关控件
//			strRlt = ((CJSwitchView) view).isChecked() ? "男" : "女";
		case 3:
			break;
		default:
			break;
		}
		return strRlt;
	}
}
